package ControlLayer;
import ModelLayer.*;
import java.util.ArrayList;
/**
 * 
 * @Author (Alexander Hvidberg, Dennis Kirkebak & Thomas Kulmbach)
 * @Team (Group 1)
 * @Version (08/11/13)
 * 
 */
public class AddressCtr
{
    private static AddressCtr instance;
    private AddressBook addressBook;
    //declare instance variables to reference containers
    //passed as arguments from the main class
    
    //Address container is to be passed as parameter from the main controller
    private AddressCtr()
    {
       addressBook = AddressBook.getInstance();
    }
    
    public static AddressCtr getInstance(){
        if(instance == null){
            instance = new AddressCtr();
        }
        return instance;
    }
        
    //Dummy implementation: after implementing the model layer 
    //objects of class Person are to be returned, not String
    public String getPerson(int id)
    {
        return addressBook.findPersonById(id).printDetails();
        //this method is to search the container for a person
        //with an id-number equal to the parameter id
        //when person is found, the method is to call print-methods in the TUI layer
        }
    public Person getPersonById(int id)
    {
        return addressBook.findPersonById(id);
        }
    public String getPersonByPhone(String phone)
    {
        if(addressBook.findPersonByPhoneNumber(phone)==null){
            return "\f Person could not be found";
        }
        else{
        return addressBook.findPersonByPhoneNumber(phone).printDetails();
       }
    }
    
    public Person returnPersonByPhone(String phone){
        return addressBook.findPersonByPhoneNumber(phone);
    }
    
    
    public void createPerson( String name, String address, String postalCode, String city, String phoneNumber)
    {   
      addressBook.createPerson(name, address, postalCode, city, phoneNumber);
    }
    
    public void deletePerson(int id)
    {
        addressBook.deletePersonById(id);
    }
    
    public void updatePerson(int id, String name, String address, String postalCode, String city, String phoneNumber)
    {
        addressBook.updatePerson(id, name, address, postalCode, city, phoneNumber);
    }
    
    public String printDetailList(){
        return addressBook.printDetailList();
    }
    
    public ArrayList listAllPersons()
    {
          return addressBook.getPersonList();
    }
}
